package com.blockchain.console.servlets.system.sup;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blockchain.console.service.system.SupUserManage;
import com.blockchain.console.service.system.entity.SupUser;
import com.blockchain.console.service.trading.TradingManage;
import com.blockchain.console.service.trading.entity.XlbEntity;
import com.blockchain.console.servlets.system.AbstractSystemServlet;
import com.blockchain.framework.service.ServiceSession;
import com.blockchain.framework.service.query.PagingResult;
import com.blockchain.util.parser.IntegerParser;

public class UpdateSupUser extends AbstractSystemServlet {
	private static final long serialVersionUID = 1L;

	@Override
	protected void processGet(HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		int id = IntegerParser.parse(request.getParameter("id"));
		SupUserManage supUserManage = serviceSession
				.getService(SupUserManage.class);
		SupUser supser = supUserManage.get(id);
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		PagingResult<XlbEntity> xlbs = tsradingManage.xlbSearch();
		request.setAttribute("coinList", xlbs);
		request.setAttribute("supUser", supser);
		forwardView(request, response, getClass());
	}

	@Override
	protected void processPost(final HttpServletRequest request,
			HttpServletResponse response, ServiceSession serviceSession)
			throws Throwable {
		SupUserManage supUserManage = serviceSession
				.getService(SupUserManage.class);
		TradingManage tsradingManage = serviceSession.getService(TradingManage.class);
		String password = request.getParameter("password");
		String name = request.getParameter("name");
		String status = request.getParameter("status");
		int id = IntegerParser.parse(request.getParameter("id"));
		int coinid = IntegerParser.parse(request.getParameter("coinId"));
		String sjh = request.getParameter("sjh");
		String coinName = tsradingManage.getXlb(coinid).zwm;
		supUserManage.update(id, password, name, status,sjh, coinid, coinName);
		sendRedirect(request, response,
				getController().getURI(request, SupUserList.class));
	}

	@Override
	protected void onThrowable(HttpServletRequest request,
			HttpServletResponse response, Throwable throwable)
			throws ServletException, IOException {
		super.onThrowable(request, response, throwable);
	}
}
